export function getMaxFloor(treeData) {
  let max = 0;
  function each(data, floor) {
    data.forEach((e) => {
      e.floor = floor;
      if (floor > max) {
        max = floor;
      }
      if (
        ((e.show && floor === 0) || floor > 0) &&
        e.children &&
        e.children.length > 0
      ) {
        each(e.children, floor + 1);
      }
    });
  }
  each(treeData, 0);
  return max;
}

export function getParentId(list, id, key) {
  for (let i in list) {
    if (list[i][key] === id) {
      return [list[i]];
    }
    if (list[i].children) {
      let node = getParentId(list[i].children, id, key);
      if (node !== undefined) {
        return node.concat(list[i]);
      }
    }
  }
}

export function getChildNode(nodes, item, arr) {
  for (let el of nodes) {
    if (el.menuId === item) {
      arr.push(el.menuId);
      if (el.children) {
        childsNodeDeepWay(el.children, arr);
      }
    } else if (el.children) {
      getChildNode(el.children, item, arr);
    }
  }
  return arr;
}
function childsNodeDeepWay(nodes, arr) {
  if (nodes)
    nodes.forEach((ele) => {
      arr.push(ele.menuId);
      if (ele.children) {
        childsNodeDeepWay(ele.children, arr);
      }
    });
}
